﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace MetaCollection.Framework.Helpers
{
	/// <summary>
	/// This class exposes a single helper function that validates a given string using a compiled
	/// regular expression to see if the string fits the format of a GUID.
	/// </summary>
	public static class GuidHelper
	{
		private static Regex guidFormat = new Regex(@"^({|\()?[A-Fa-f0-9]{8}-([A-Fa-f0-9]{4}-){3}[A-Fa-f0-9]{12}(}|\))?$", RegexOptions.Compiled | RegexOptions.CultureInvariant);

		/// <summary>
		/// Determines whether the specified value is GUID.
		/// </summary>
		/// <param name="value">The value.</param>
		/// <returns>
		/// 	<c>true</c> if the specified value is GUID; otherwise, <c>false</c>.
		/// </returns>
		public static bool IsGuid(string value)
		{
			if (!string.IsNullOrEmpty(value))
			{
				return guidFormat.IsMatch(value);
			}
			return false;
		}
	}
}
